package com.prosay.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 在线用户列表
 * @author dongliang
 *
 */
public class OnlineServlet extends HttpServlet {
    
	public void service(HttpServletRequest request,HttpServletResponse response) throws IOException{
		//System.out.println("****打印在线用户列表****");
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");

		PrintWriter out = response.getWriter();
		//out.println("打印在线用户列表");
		//out.println("<br/>");
		out.println("<html>");
		out.println("<head>");
		out.println("<meta charset='utf-8'>");
		out.println("<meta http-equiv='refresh' content='1'>");
        out.println("</head>");
        out.println("<body>");
        out.println("<ul>");

		ServletContext application = this.getServletContext();
		List<String> onLineUser = (List<String>)application.getAttribute("users");
		for(String list:onLineUser){
			out.println("<li>"+list+"</li>");
		}
		out.println("</ul>");
		out.println("</body>");
		out.println("</html>");

	}
}
